//
// Created by Zhangwj on 2023/9/27.
//

#include "AddExpNode.h"

std::unique_ptr<AddExpNode> AddExpNode::AddExpParser(Parser &parser) {
    // AddExp → MulExp | AddExp ('+' | '−') MulExp
    //改写为 AddExp -> MulExp { ('+' | '−') MulExp } 遍历时要改成原来的语法书形状
    std::unique_ptr<AddExpNode> addExpNode = std::make_unique<AddExpNode>();
    addExpNode->MulExps.push_back(MulExpNode::MulExpParser(parser));
    while (parser.getLexType(0) == LexType::PLUS || parser.getLexType(0) == LexType::MINU) {
        addExpNode->Ops.push_back(parser.getLexType(0));
        parser.next();
        addExpNode->MulExps.push_back(MulExpNode::MulExpParser(parser));
    }
    return addExpNode;
}
